<html>
<head>
    <title>移动教学信息管理系统 - 后台</title>
    <link href="/static/css/semantic.css" rel="stylesheet"/>
    <style>
body{font-family: "Microsoft YaHei" !important;}
body {
    background-color: #FFFFFF;
}
.ui.menu .item img.logo {
    margin-right: 1.5em;
}
.main.container {
    margin-top: 7em;
}
.wireframe {
    margin-top: 2em;
}
.ui.footer.segment {
    margin: 5em 0em 0em;
    padding: 5em 0em;
}
    </style>
</head>
<body>
    <table class="ui celled striped table">
        <thead>
        <tr><th colspan="4">资源管理
            <button class="button ui primary" onclick="$('.ui.modal').modal('show');">添加</button>
        </th>
        </tr>
        <tr>
            <th>ID</th>
            <th>名称</th>
            <th>类型</th>
            <th>描述</th>
            <th>附件</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>

        <#list list as i>
        <tr>
            <td class="collapsing"> ${i.id} </td>
            <td>${i.name}</td>
            <td>${i.type}</td>
            <td>${i.desc!}</td>
            <td>
                <#if i.attach??><button class="button ui blue" onclick="location.href='/download/${i.id}'">下载</button></#if>
            </td>
            <td class="right aligned collapsing">
                <button class="button ui orange" onclick="$('.ui.modal').modal('show');onUpdate('${i.id}','${i.name!}','${i.type!}','${i.desc!}')">修改</button>
                <button class="button ui red" onclick="del('${i.id}')">删除</button>
            </td>
        </tr>
        </#list>
        </tbody>
    </table>
<div class="ui modal" style="width: 300px; padding: 15px;margin-left: -200px">
    <form class="ui form five" method="post" action="/resource" enctype="multipart/form-data">
        <input type="hidden" name="id"/>
        <div class="field">
            <input type="text" name="name" placeholder="名称">
        </div>
        <div class="field">
            <input type="text" name="type" placeholder="类型">
        </div>
        <div class="field">
            <input type="text" name="desc" placeholder="描述">
        </div>
        <div class="field">
            附件：<input type="file" name="attach1">
        </div>
        <button class="ui button primary" type="submit" >提交</button>
        <button class="ui button" type="button" onclick="$('.ui.modal').modal('hide');">取消</button>
    </form>
</div>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/semantic.min.js"></script>
<script type="text/javascript">
function del(id) {
    $.post('/res/delete/'+id,function (data) {
        alert('删除成功');
        location.reload();
    })
}
function onUpdate(id,name,type,desc) {
    $('input[name=id]').val(id);
    $('input[name=name]').val(name);
    $('input[name=type]').val(type);
    $('input[name=desc]').val(desc);
}
</script>
</body>
</html>